import { IdBO, IdsBO } from "@/constant/types"
import { RequestConfigExtra, usePost } from "@/http"

const queryOptions: RequestConfigExtra = {
    success: false,
    error: true
}

const options: RequestConfigExtra = {
    success: true,
    error: true
}

const search = async (params: any) => {
    return usePost("/system/role/search", params ?? {}, queryOptions)
}

const disable = async (params: IdsBO) => {
    return usePost("/system/role/disable", params ?? {}, options)
}

const enable = async (params: IdsBO) => {
    return usePost("/system/role/enable", params ?? {}, options)
}

const deleteBatch = async (params: IdsBO) => {
    return usePost("/system/role/delete", params ?? {}, options)
}

const add = async (params: Recordable) => {
    return usePost("/system/role/add", params ?? {}, options)
}

const update = async (params: Recordable) => {
    return usePost("/system/role/update", params ?? {}, options)
}

const permissionTree = async () => {
    return usePost("/system/permission/tree", {}, queryOptions)
}

const permissionIds = async (params: IdBO) => {
    return usePost("/system/role/permissionIds", params, queryOptions)
}

const allocPermission = async (params: Recordable) => {
    return usePost("/system/role/alloc/permission", params, options)
}

export const api = { search, disable, enable, delete: deleteBatch, add, update, permissionTree, permissionIds, allocPermission }
